perf(pytest): cache path resolution to reduce discovery time for large test suites#35
Closed
perf(pytest): cache path resolution to reduce discovery time for large test suites#35
Conversation
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement caching for path resolution results
perf(pytest): cache path resolution to reduce discovery time for large test suites
Dec 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test discovery for large suites (~150k tests) shows 10x slowdown vs native pytest due to redundant path operations in
pytest_sessionfinishhook. Profiling indicates repeatedpathlib.Path.cwd()calls,os.fspath()conversions, and exception-based dictionary lookups dominate execution time.Changes
Caching infrastructure
_path_cache(node paths by id),_path_to_str_cache(string conversions),_CACHED_CWD(working directory)cached_fsdecode(): memoizedos.fspath()wrapper used for dictionary keys throughout tree buildingModified
get_node_path()Control flow optimization
try/except KeyErrorwithdict.get()in 5 hotpath locations:process_parameterized_test(),build_test_tree(),build_nested_folders()Example
Expected improvement: 10-20s reduction for 150k test discovery, minimal memory overhead (~50-100KB).
Original prompt
fantastic begin PR for: Strategy 1: Cache Path Resolution Results (CRITICAL - Quick Win)
[Chronological Review: The conversation began with the user requesting a review of an issue related to performance in the vscode-python repository. The user asked for an analysis of the code, identification of potential slowdowns, and mediation strategies to improve performance. The user then inquired about the specific function "pytest_sessionfinish" and whether it was the source of the performance issues. Following this, the user requested an update to a markdown document they had created regarding performance analysis. The user later asked to begin a pull request for a specific strategy related to caching path resolution results.][Intent Mapping:
[Technical Inventory:
[Code Archaeology:
[Progress Assessment:
[Context Validation: All critical information for continuation is captured, including user requests for analysis, document updates, and pull request initiation.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: - "review this issue- it is about performance..." - Analyze performance issues in the vscode-python repository. - "so do you see these problems coming from 'pytest_sessionfinish'..." - Clarify the source of performance problems. - "update the doc you made please" - Update the performance analysis document. - "fantastic begin PR for: Strategy 1: Cache Path Resolution Results (CRITICAL - Quick Win)" - Start a pull request for a caching strategy. - Session Context: The conversation has focused on performance analysis, identifying potential slowdowns, and proposing strategies for improvement. - User Intent Evolution: The user has moved from seeking analysis to requesting document updates and initiating a pull request for a specific strategy.- Technical Foundation:
- Repository: vscode-python
- Current branch: resonant-duck
- Default branch: main
- Key function: pytest_sessionfinish
- Proposed strategy: Caching path resolution results.
- Codebase Status:
- File Name: pytest-performance-analysis-proposal.md
- Purpose: Document performance analysis and proposed strategies.
- Current State: User indicated edits were made, but specifics were not provided.
- Key Code Segments: Not specified in the conversation.
- Dependencies: Related to performance issues in the vscode-python repository.
- Problem Resolution:
- Issues Encountered: Performance issues related to the pytest framework.
- Solutions Implemented: User proposed caching path resolution results as a strategy.
- Debugging Context: Ongoing analysis of performance issues.
- Lessons Learned: Importance of identifying specific functions contributing to performance slowdowns.
- Progress Tracking:
- Completed Tasks: Initial performance analysis requested.
- Partially Complete Work: Performance analysis document is in progress and requires updates.
- Validated Outcomes: User is satisfied with the initial analysis and ready to proceed with a pull request.
- Active W...
Created from VS Code.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.